/*
 * Copyright (C) 2008 Universidade Federal de Campina Grande
 *  
 * This file is part of OurGrid. 
 *
 * OurGrid is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) 
 * any later version. 
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details. 
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package org.ourgrid.acceptance.worker;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.ourgrid.acceptance.util.WorkerAcceptanceUtil;
import org.ourgrid.acceptance.util.worker.Req_004_Util;
import org.ourgrid.acceptance.util.worker.Req_006_Util;
import org.ourgrid.acceptance.util.worker.Req_079_Util;
import org.ourgrid.acceptance.util.worker.Req_080_Util;
import org.ourgrid.acceptance.util.worker.Req_081_Util;
import org.ourgrid.acceptance.util.worker.Req_084_Util;
import org.ourgrid.acceptance.util.worker.Req_087_Util;
import org.ourgrid.acceptance.util.worker.Req_088_Util;
import org.ourgrid.acceptance.util.worker.Req_090_Util;
import org.ourgrid.acceptance.util.worker.Req_091_Util;
import org.ourgrid.acceptance.util.worker.Req_092_Util;
import org.ourgrid.acceptance.util.worker.Req_120_Util;
import org.ourgrid.acceptance.util.worker.Req_121_Util;
import org.ourgrid.common.interfaces.Worker;
import org.ourgrid.common.interfaces.WorkerClient;
import org.ourgrid.common.interfaces.management.RemoteWorkerManagementClient;
import org.ourgrid.common.interfaces.management.WorkerManagementClient;
import org.ourgrid.common.interfaces.to.WorkerStatus;
import org.ourgrid.common.util.JavaFileUtil;
import org.ourgrid.reqtrace.ReqTest;
import org.ourgrid.worker.WorkerComponent;
import org.ourgrid.worker.dao.EnvironmentDAO;
import org.ourgrid.worker.utils.RandomNumberUtil;

import br.edu.ufcg.lsd.commune.container.logging.CommuneLogger;
import br.edu.ufcg.lsd.commune.identification.ContainerID;
import br.edu.ufcg.lsd.commune.identification.DeploymentID;
import br.edu.ufcg.lsd.commune.processor.filetransfer.IncomingTransferHandle;
import br.edu.ufcg.lsd.commune.processor.filetransfer.OutgoingTransferHandle;
import br.edu.ufcg.lsd.commune.processor.filetransfer.TransferHandle;
import br.edu.ufcg.lsd.commune.test.AcceptanceTestUtil;

@ReqTest(reqs="REQ081")
public class Req_081_Test extends WorkerAcceptanceTestCase {
	
	private DeploymentID peerID;
	private Req_004_Util req_004_Util = new Req_004_Util(getComponentContext());
	private Req_090_Util req_090_Util = new Req_090_Util(getComponentContext());
	private Req_092_Util req_092_Util = new Req_092_Util(getComponentContext());
	private Req_080_Util req_080_Util = new Req_080_Util(getComponentContext());
	private Req_081_Util req_081_Util = new Req_081_Util(getComponentContext());
	private Req_084_Util req_084_Util = new Req_084_Util(getComponentContext());
	private Req_079_Util req_079_Util = new Req_079_Util(getComponentContext());
	private Req_006_Util req_006_Util = new Req_006_Util(getComponentContext());
	private Req_121_Util req_121_Util = new Req_121_Util(getComponentContext());
	private Req_120_Util req_120_Util = new Req_120_Util(getComponentContext());
	private Req_087_Util req_087_Util = new Req_087_Util(getComponentContext());
	private Req_088_Util req_088_Util = new Req_088_Util(getComponentContext());	
	private Req_091_Util req_091_Util = new Req_091_Util(getComponentContext());
		
//	private static final String playpenDirName  = "worker-4962768465676381896";
	
	@Before
	public void setUp() throws Exception {
		super.setUp();
		String peerPubKey = workerAcceptanceUtil.simulateAuthentication();
		peerID = new DeploymentID(new ContainerID("username", "server", "module", peerPubKey), "peer");
		
	}

	/**
	 *    1. Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: An unknown client tried to recover the file [$PLAYPEN/file1]. Unknown client public key: [mgPublicKey222].
	 *    5. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    6. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: An unknown client tried to recover the files [$PLAYPEN/file1, $PLAYPEN/file2]. Unknown client public key: [mgPublicKey222].
	 *    7. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    8. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *    9. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   10. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: An unknown client tried to recover the files [$PLAYPEN/file1]. Unknown client public key: [mgPublicKey1].
	 *   11. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   12. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: An unknown client tried to recover the files [$PLAYPEN/file1, $PLAYPEN/file2]. Unknown client public key: [mgPublicKey1].
	 * 
	 */
	@ReqTest(test=" AT-081.1", reqs="REQ080")
	@Test public void test_at_081_1_UnknownClientTriesToRecoverFiles() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();

		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesByUnknownClient(component, 1, "mgPublicKey222", "$PLAYPEN/file1");
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID broker1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		req_079_Util.startWorkSuccessfully(component, worker, broker1ID);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesByUnknownClient(component, 1, "mgPublicKey222", "$PLAYPEN/file1", "$PLAYPEN/file2");
		
		//The master peer sends a stopWorking message to the Worker
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID broker2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		req_079_Util.startWorkSuccessfully(component, worker, broker2ID);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesByUnknownClient(component, 1, broker1ID.getPublicKey(), "$PLAYPEN/file1");

		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesByUnknownClient(component, 1, broker1ID.getPublicKey(), "$PLAYPEN/file1", "$PLAYPEN/file2");
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [$PLAYPEN/file1], but this Worker was not commanded to start the work yet. This message was ignored. Client public key: [mgPublicKey1].
	 *    5. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [$PLAYPEN/file1, $PLAYPEN/file2], but this Worker was not commanded to start the work yet. This message was ignored. Client public key: [mgPublicKey1].
	 *    6. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    7. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *    8. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    9. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [$PLAYPEN/file1], but this Worker was not commanded to start the work yet. This message was ignored. Client public key: [mgPublicKey222].
	 *   10. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1, $PLAYPEN/file2], but this Worker was not commanded to start the work yet. This message was ignored. Client public key: [mgPublicKey222].
	 *           
	 */
	@ReqTest(test=" AT-081.2", reqs="REQ080")
	@Test public void test_at_081_2_ClientTriesToRecoverFilesOnUnstartedWorker() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();

		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesOnUnstartedWorker(component, 1, "mgPublicKey1", "$PLAYPEN/file1");
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesOnUnstartedWorker(component, 1, "mgPublicKey1", "$PLAYPEN/file1", "$PLAYPEN/file2");
		
		//The master peer sends a stopWorking message to the Worker
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesOnUnstartedWorker(component, 1, "mgPublicKey222", "$PLAYPEN/file1");

		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesOnUnstartedWorker(component, 1, "mgPublicKey222", "$PLAYPEN/file1", "$PLAYPEN/file2");
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [$PLAYPEN/file1], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey1].
	 *    6. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [$PLAYPEN/file1, $PLAYPEN/file2], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey1].
	 *    7. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    8. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *    9. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   10. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   11. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [$PLAYPEN/file1], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey222].
	 *   12. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1, $PLAYPEN/file2], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey222].
	 *           
	 */
	@ReqTest(test=" AT-081.3", reqs="REQ080")
	@Test public void test_at_081_3_ClientTriesToRecoverFilesOnWorkerThatDidNotStartToExecuteComand() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();

		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid1ID.getPublicKey(), "$PLAYPEN/file1");
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid1ID.getPublicKey(), "$PLAYPEN/file1", "$PLAYPEN/file2");
		
		//The master peer sends a stopWorking message to the Worker
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid2ID.getPublicKey(), "$PLAYPEN/file1");

		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid2ID.getPublicKey(), "$PLAYPEN/file1", "$PLAYPEN/file2");
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" requests to transfer the file "root/file", with size 1123 bytes and the handle "0";
	 *           * Verify if the following debug message was logged: A transfer request from the client was successfully accepted. Client public key: [mgPublicKey1]. File destination: [playpenDir/root/file]. File size: 1123 bytes. Handle: 0.
	 *           * Expect the Worker to accept the file transfer;
	 *    6. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey1].
	 *    7. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [$PLAYPEN/file1, $PLAYPEN/file2], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey1].
	 *    8. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    9. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   10. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   11. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   12. A client with the public key "mgPublicKey222" requests to transfer the file "root/file", with size 1123 bytes and the handle "0";
	 *           * Verify if the following debug message was logged: A transfer request from the client was successfully accepted. Client public key: [mgPublicKey222]. File destination: [playpenDir/root/file]. File size: 1123 bytes. Handle: 0.
	 *           * Expect the Worker to accept the file transfer;
	 *   13. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey222].
	 *   14. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1, $PLAYPEN/file2], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey222].
	 * 
	 */
	@ReqTest(test=" AT-081.4", reqs="REQ080")
	@Test public void test_at_081_4_ClientTriesToRecoverFilesOnWorkerThatIsReceivingFiles() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();

		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		ContainerID senderID = myGrid1ID.getContainerID();
		
		//A client with the public key "mgPublicKey1" requests to transfer the file "file1",
		// with size 256 bytes and the handle "1"
		req_080_Util.requestToTransferFile(component, 1, senderID, "file1", 
				new IncomingTransferHandle(1, "file1", 256, "file1", "PUT", senderID), 256);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid1ID.getPublicKey(), "$PLAYPEN/file1");
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid1ID.getPublicKey(), "$PLAYPEN/file1", "$PLAYPEN/file2");
		
		//The master peer sends a stopWorking message to the Worker
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" requests to transfer the file "file1",
		// with size 256 bytes and the handle "1"
		ContainerID senderID2 = myGrid2ID.getContainerID();
		req_080_Util.requestToTransferFile(component, 1, senderID2, "file1", 
				new IncomingTransferHandle(1, "file1", 256, "file1", "PUT", senderID2), 256);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid2ID.getPublicKey(), "$PLAYPEN/file1");

		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid2ID.getPublicKey(), "$PLAYPEN/file1", "$PLAYPEN/file2");
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "echo echo"; without releasing the handle (execution blocks)
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: echo echo; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *    6. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey1].
	 *    7. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1, $PLAYPEN/file2], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey1].
	 *    8. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    9. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   10. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   11. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   12. A client with the public key "mgPublicKey222" tries to execute the remote command "echo echo"; without releasing the handle (execution blocks)
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: echo echo; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   13. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey222].
	 *   14. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2";
	 *           * Verify if the following warn message was logged: A client tried to recover the file [$PLAYPEN/file1, $PLAYPEN/file2], but the Broker cannot download files before the execution finish. This message was ignored. Client public key: [mgPublicKey222].
 	 * 
	 */
	@ReqTest(test=" AT-081.5", reqs="REQ080")
	@Test public void test_at_081_5_ClientTriesToRecoverFilesOnWorkerThatDidNotFinishToExecuteComand() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();
		
//		Map<String, String> properties = component.getContainer().getContext().getProperties();

		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "echo echo"
		//The WorkerExecutionClient does not receive an execution result
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		String storageDir = component.getDAO(EnvironmentDAO.class).getStorageDir();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		req_084_Util.remoteExecute(component, worker, workerClient, myGrid1ID, requestID, envVars, 
				"echo echo", true, true, false, false, playpenDir, storageDir, 0);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid1ID.getPublicKey(), "$PLAYPEN/file1");
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid1ID.getPublicKey(), "$PLAYPEN/file1", "$PLAYPEN/file2");
		
		//The master peer sends a stopWorking message to the Worker
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc =  req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "echo echo"
		//The WorkerExecutionClient does not receive an execution result
		req_084_Util.remoteExecute(component, worker, workerClient, myGrid2ID, requestID, envVars, 
				"echo echo", true, true, false, false, playpenDir, storageDir, 2);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid2ID.getPublicKey(), "$PLAYPEN/file1");

		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/file1", "$PLAYPEN/file2"
		req_081_Util.requestToRecoverFilesBeforeExecutionFinish(component, 1, myGrid2ID.getPublicKey(), "$PLAYPEN/file1", "$PLAYPEN/file2");
	}

	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    6. A client with the public key "mgPublicKey1" requests to recover the file "null";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error occured on solving path. This message was ignored. Error cause: [File path is null]. File path: [null]. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
	 *    7. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    8. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 * 			 * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
     *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    9. A client with the public key "mgPublicKey1" requests to recover the files "$ABC/temp", "$PLAYPEN/../../$STORAGE";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [Invalid variable found.]. File path: [$ABC/temp. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
	 *   10. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   11. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   12. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   13. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   14. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1;
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *   15. A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/../temp";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [File path is not relative to "absolutePath" directory.]. File path: [$STORAGE/../temp]. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
	 *   16. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   17. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1;
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *   18. A client with the public key "mgPublicKey222" requests to recover the files "$PLAYPEN/teste/$STORAGE/temp", "$PLAYPEN/../../system";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [Invalid variable found.]. File path: [$PLAYPEN/teste/$STORAGE/temp]. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
	 *   19. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   20. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   21. Copy the file "foo1" to playpen directory;
	 *   22. A client with the public key "mgPublicKey222" requests to recover the files "foo1", "$PLAYPEN/foo1", "foo2";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [There are files with same path.]. File path: [$PLAYPEN/file1]. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
 	 * 
	 */
	@ReqTest(test=" AT-081.6", reqs="REQ080")
	@Test public void test_at_081_6_ClientTriesToRecoverFilesWithInvalidDirectory() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();
		
		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
//		Random random = new Random();
		RandomNumberUtil.setSeed(0L);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);
		
		AcceptanceTestUtil.publishTestObject(component, myGrid1ID, workerClient, WorkerClient.class);
		//A client with the public key "mgPublicKey1" requests to recover the file "null" - expect a warn to be logged
		req_081_Util.requestToRecoverFilesWithNullFiles(component, requestID, myGrid1ID.getPublicKey(), workerClient);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN/foo1", playpenDir, storageDir, 1);
		
		//A client with the public key "mgPublicKey1" requests to recover the files "$ABC/temp",
		// "$PLAYPEN/../../$STORAGE" - expect a warn to be logged
		req_081_Util.requestToRecoverFilesWithInvalidVariable(component, requestID, myGrid1ID.getPublicKey(),
				"$ABC" + File.separator + "temp", workerClient, "$ABC" + File.separator + "temp",
				"$PLAYPEN"+File.separator+".."+File.separator+".."+File.separator+"$STORAGE");
		
		//The master peer sends a stopWorking message to the Worker
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		RandomNumberUtil.setSeed(0L);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $PLAYPEN\\\\worker-.+/foo", playpenDir, storageDir, 2);

		//A client with the public key "mgPublicKey222" requests to recover the files "$STORAGE/../temp"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(myGrid2ID.getPublicKey());
		req_081_Util.requestToRecoverFilesWithNotRelativePath(component, requestID, myGrid2ID.getPublicKey(),
				"$STORAGE/../temp", workerClient,  storageDir, "$STORAGE/../temp");
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $PLAYPEN/foo1", playpenDir, storageDir, 3);
		
		//A client with the public key "mgPublicKey222" requests to recover the files "$PLAYPEN/teste/$STORAGE/temp",
		// "$PLAYPEN/../../system" - expect a warn to be logged
		req_081_Util.requestToRecoverFilesWithInvalidVariable(component, requestID, myGrid2ID.getPublicKey(),
				"$PLAYPEN/teste/$STORAGE/temp",	workerClient, "$PLAYPEN/teste/$STORAGE/temp", "$PLAYPEN/../../system");
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $PLAYPEN/foo1", playpenDir, storageDir, 4);
		
		//Copy the file "foo1" to playpen directory
		String completeFilePath = playpenDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFilePath);

		//A client with the public key "mgPublicKey222" requests to recover the files "foo1", "$PLAYPEN/foo1", "foo2"
		// expect a warn to be logged
		req_081_Util.requestToRecoverFilesWithSamePaths(component, requestID, myGrid2ID.getPublicKey(), "$PLAYPEN/foo1", workerClient,
				"foo1", "$PLAYPEN/foo1", "foo2");
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    6. A client with the public key "mgPublicKey1" requests to recover the file "foo3";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [File not found.]. File path: [foo3]. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *    7. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    8. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *    9. Copy the file "foo2" to playpen directory
	 *   10. Set the file "foo2" unreadable
	 *   11. A client with the public key "mgPublicKey1" requests to recover the files "foo2", "$PLAYPEN/foo3";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [File cannot be read.]. File path: [foo2]. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
	 *   12. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   13. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   14. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   15. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   16. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   17. A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo2";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [File not found.]. File path: [foo2]. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   18. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   19. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1;";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   20. Copy the file "foo3" to storage directory
	 *   21. Set the file "foo3" unreadable
	 *   22. A client with the public key "mgPublicKey222" requests to recover the files "$STORAGE/foo3", "foo1";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [File cannot be read.]. File path: [$STORAGE/foo3]. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
 	 * 
	 */
	@ReqTest(test=" AT-081.7", reqs="REQ080")
	@Test public void test_at_081_7_ClientTriesToRecoverFilesButErrorOcurredOnReadingFile() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();
		
		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		RandomNumberUtil.setSeed(0L);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("$STORAGE", storageDir);
		envVars.put("$PLAYPEN", playpenDir);
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);

		//A client with the public key "mgPublicKey1" requests to recover the file "foo3"
		// expect a warn to be logged
		req_081_Util.requestToRecoverAnInexistentFile(component, requestID, myGrid1ID.getPublicKey(), playpenDir + 
				File.separator + "foo3", workerClient, "foo3");
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN/foo1", playpenDir, storageDir, 1);
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("$STORAGE", storageDir);
		envVars.put("$PLAYPEN", playpenDir);

		//Copy the file "foo2" to playpen directory
		String completeFilePath = playpenDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFilePath);
		
		//Set the file "foo2" unreadable
		File file = new File(completeFilePath);
		boolean OSImplementReadable = JavaFileUtil.setNonReadable(file);
		
		//A client with the public key "mgPublicKey1" requests to recover the files "foo2", "$PLAYPEN/foo3"
		// expect a warn to be logged

		if(OSImplementReadable){
			req_081_Util.requestToRecoverAnUnreadableFile(component, requestID, myGrid1ID.getPublicKey(), "foo2",
					workerClient, "foo2");
		}
		
		//The master peer sends a stopWorking message to the Worker
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $STORAGE/foo1", playpenDir, storageDir, 2);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo2"
		// expect a warn to be logged
		req_081_Util.requestToRecoverAnInexistentFile(component, requestID, myGrid2ID.getPublicKey(), storageDir +
				File.separator + "foo2", workerClient, "$STORAGE/foo2");
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid2ID.getPublicKey());
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $PLAYPEN/foo1", playpenDir, storageDir, 3);
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("$STORAGE", storageDir);
		envVars.put("$PLAYPEN", playpenDir);

		//Copy the file "foo3" to storage directory
		completeFilePath = storageDir + File.separator + "foo3";
		WorkerAcceptanceUtil.createFile(completeFilePath);
		
		//Set the file "foo3" unreadable
		file = new File(completeFilePath);
		OSImplementReadable = JavaFileUtil.setNonReadable(file);
		
		//A client with the public key "mgPublicKey222" requests to recover the files "$STORAGE/foo3", "foo1"
		// expect a warn to be logged
		if(OSImplementReadable){
			req_081_Util.requestToRecoverAnUnreadableFile(component, requestID, myGrid2ID.getPublicKey(),
					"$STORAGE/foo3", workerClient, "$STORAGE/foo3", "foo1");
		}
	}

	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    6. Copy the file "foo1" to playpen directory
	 *    7. A client with the public key "mgPublicKey1" requests to recover the file "foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *    8. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    9. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; $PLAYPEN/touch foo2; touch $STORAGE/foo3; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *   10. Copy the file "foo1" to playpen directory
	 *   11. Copy the file "foo2" to storage directory
	 *   12. A client with the public key "mgPublicKey1" requests to recover the files "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *   13. A client with the public key "mgPublicKey1" requests to recover the files "foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files that already being uploaded. File path: [playpenDir/foo1]. Client public key: [mgPublicKey1].
	 *   14. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   15. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *   16. Copy the file "foo1" to playpen directory
	 *   17. A client with the public key "mgPublicKey1" requests to recover the files "foo1", "foo3";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [File not found.]. File path: [foo3]. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
	 *   18. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   19. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   20. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   21. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   22. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo2; foo3";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo2; $PLAYPEN/touch foo3; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   23. Copy the file "foo2" to storage directory
	 *   24. A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Client public key: [mgPublicKey222]. Handle: 1
	 *           * Expect the Worker to start the transfer;
	 *   25. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   26. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1; touch $STORAGE/foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; touch $STORAGE/foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   27. Copy the file "foo1" to playpen directory
	 *   28. A client with the public key "mgPublicKey222" requests to recover the files "foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. Worker starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *   29. A client with the public key "mgPublicKey222" requests to recover the files "foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files that already being uploaded. File path: [playpenDir/foo1]. Client public key: [mgPublicKey222].
	 *   30. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   31. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1"
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *   32. Copy the file "foo1" to playpen directory
	 *   33. A client with the public key "mgPublicKey1" requests to recover the files "foo1", "foo3";
	 *           * Verify if the following error message was logged: The client tried to recover the files, but a error ocurred on solving path. This message was ignored. Error cause: [File not found.]. File path: [foo3]. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the IO_ERROR type
	 *   34. A client with the public key "mgPublicKey1" requests to recover the files "foo1";
	 *           * Verify if the following warn message was logged: A client tried to recover the files [foo1]. This message was ignored, because a error already ocurred. Client public key: [mgPublicKey1].
	 * 
	 */
	@ReqTest(test=" AT-081.8", reqs="REQ080")
	@Test public void test_at_081_8_WorkerStartsTheTransferWithSucess() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker(false);
		
		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);
		
		//Copy the file "foo1" to playpen directory
		String completeFile1Path = playpenDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "foo1");
	
		//A client with the public key "mgPublicKey1" sends a startWork message
		List<TransferHandle> handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "foo1", "foo1", "PUT", myGrid1ID));
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID, handles);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1;", playpenDir, storageDir, 1);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to storage directory
		String completeFile2Path = storageDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey1" requests to recover the files "$PLAYPEN/foo1", "$STORAGE/foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$PLAYPEN"+File.separator+"foo1", "$STORAGE"+File.separator+"foo2");
				
		//A client with the public key "mgPublicKey1" requests to recover the files "foo1"
		req_081_Util.requestToRecoverFilesThatAlreadyBeingUploaded(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				"foo1", playpenDir, storageDir, "foo1");
				
		//A client with the public key "mgPublicKey1" sends a startWork message
		handles.add(new OutgoingTransferHandle(2, "foo2", "foo2", "PUT", myGrid1ID));
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID, handles);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1;", playpenDir, storageDir, 2);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		
		//A client with the public key "mgPublicKey1" requests to recover the files "foo1", "foo3"
		// expect a warn to be logged
		req_081_Util.requestToRecoverAnInexistentFile(component, 1, myGrid1ID.getPublicKey(), playpenDir + File.separator + "foo3",
				workerClient, "foo1", "foo3");
				
		//The master peer sends a stopWorking message to the Worker
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);

		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo2; $PLAYPEN/touch foo3"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid2ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo2; $PLAYPEN"+File.separator+"touch foo3", playpenDir, storageDir, 3);		
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		//Copy the file "foo2" to storage directory
		completeFile2Path = storageDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$STORAGE"+File.separator+"foo2");
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "foo2", "foo2", "PUT", myGrid2ID));
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid2ID, handles);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1; touch $STORAGE/foo2"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars,	"touch $PLAYPEN"+File.separator+"foo1; touch $STORAGE"+File.separator+"foo2",
				playpenDir, storageDir, 4);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to storage directory
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey222" requests to recover the files "foo1", "$STORAGE/foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "foo1", "$STORAGE"+File.separator+"foo2");
		
		//A client with the public key "mgPublicKey222" requests to recover the files "foo1"
		req_081_Util.requestToRecoverFilesThatAlreadyBeingUploaded(component, requestID, myGrid2ID.getPublicKey(), workerClient,
				"foo1", playpenDir, storageDir, "foo1");
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "foo1", "foo1", "PUT", myGrid2ID));
		handles.add(new OutgoingTransferHandle(2, "foo2", "foo2", "PUT", myGrid2ID));
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid2ID, handles);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1", playpenDir, storageDir, 5);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//A client with the public key "mgPublicKey222" requests to recover the files "foo1", "$STORAGE/foo3"
		req_081_Util.requestToRecoverAnInexistentFile(component, 1, myGrid2ID.getPublicKey(), storageDir + File.separator + "foo3",
				workerClient, "foo1", "$STORAGE"+File.separator+"foo3");
		
		//A client with the public key "mgPublicKey222" requests to recover the files "foo1" - expect a warn to be logged
		req_081_Util.requestToRecoverFilesOnWorkerWithError(component, 1, workerClient, myGrid2ID.getPublicKey(), "foo1");
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1]."
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    6. Copy the file "foo1" to playpen directory
	 *    7. A client with the public key "mgPublicKey1" requests to recover the file "foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *    8. A client with the public key "mgPublicKey222" sends a file reject message with handle "1";
	 *           * Verify if the following warn message was logged: The worker received a file reject message from the unknown client. This message was ignored. Client public key: [mgPublicKey222].
	 *    9. A client with the public key "mgPublicKey1" sends a file reject message with handle "2";
	 *           * Verify if the following warn message was logged: The worker received a file reject message with unknown handle. This message was ignored.  Handle: 2. Client public key: [mgPublicKey1].
	 *   10. A client with the public key "mgPublicKey1" sends a file reject message with handle "1";
	 *           * Verify if the following error message was logged: The worker received a file reject message from the client. This message was successfully accepted. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   11. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   12. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *   13. Copy the file "foo1" to playpen directory
	 *   14. Copy the file "foo2" to storage directory
	 *   15. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2.  Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *   16. A client with the public key "mgPublicKey1" sends a file reject message with handle "1";
	 *           * Verify if the following error message was logged: The worker received a file reject message from the client. This message was successfully accepted. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   17. A client with the public key "mgPublicKey1" sends a file reject message with handle "2";
	 *           * Verify if the following warn message was logged: The worker received a file reject message from the client. This message was ignored, because a error already ocurred. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey1].
	 *   18. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   19. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   20. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   21. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   22. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   23. Copy the file "foo1" to storage directory
	 *   24. Copy the file "foo2" to playpen directory
	 *   25. A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *   26. A client with the public key "mgPublicKey222" sends a file reject message with handle "1";
	 *           * Verify if the following error message was logged: The worker received a file reject message from the client. This message was successfully accepted. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   27. A client with the public key "mgPublicKey222" sends a file reject message with handle "2";
	 *           * Verify if the following warn message was logged: The worker received a file reject message from the client. This message was ignored, because a error already ocurred. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 * 
	 */
	@ReqTest(test=" AT-081.9", reqs="REQ080")
	@Test public void test_at_081_9_FileRejectedAfterWorkerStartedToTransferFile() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();
		
		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);
		
		//Copy the file "foo1" to playpen directory
		String completeFile1Path = playpenDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "foo1");
		
		//A client with the public key "mgPublicKey1" sends a file reject message with handle "2"
		// expect a warn to be logged
		req_081_Util.receiveFileRejectWithUnknownHandle(component, workerClient, myGrid1ID.getPublicKey(), 
				new OutgoingTransferHandle(2,"", "", "", myGrid1ID));
		
		//A client with the public key "mgPublicKey1" sends a file reject message with handle "1"
		// expect a warn to be logged
		req_081_Util.receiveFileReject(component, workerClient, myGrid1ID.getPublicKey(), 
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "PUT", myGrid1ID) , completeFile1Path);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		List<TransferHandle> handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "PUT", myGrid1ID));
		
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID, handles);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1", playpenDir, storageDir, 1);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to storage directory
		String completeFile2Path = storageDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$PLAYPEN"+File.separator+"foo1", "$STORAGE"+File.separator+"foo2");
		
		//A client with the public key "mgPublicKey1" sends a file reject message with handle "2"
		// expected a error to be logged
		req_081_Util.receiveFileReject(component, workerClient, myGrid1ID.getPublicKey(), 
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid1ID), completeFile2Path);
		
		//A client with the public key "mgPublicKey1" sends a file reject message with handle "1"
		// expected a error to be logged
		req_081_Util.receiveFileRejectOnWorkerWithError(component, workerClient, myGrid1ID.getPublicKey(), 
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID), completeFile1Path);
		
		//The master peer sends a stopWorking message to the Worker
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid1ID));
		
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey(), true, handles);
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);

		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid2ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1", playpenDir, storageDir, 2);	
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		
		//Copy the file "foo1" to storage directory
		completeFile1Path = storageDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", "foo2");
		
		//A client with the public key "mgPublicKey1" sends a file reject message with handle "2"
		// expected a error to be logged
		req_081_Util.receiveFileReject(component, workerClient, myGrid2ID.getPublicKey(),
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "PUT", myGrid2ID), completeFile2Path);
		
		//A client with the public key "mgPublicKey1" sends a file reject message with handle "1"
		// expected a warn to be logged
		req_081_Util.receiveFileRejectOnWorkerWithError(component, workerClient, myGrid2ID.getPublicKey(),
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "PUT", myGrid2ID), completeFile1Path);
	}

	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1]."
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    6. Copy the file "foo1" to playpen directory
	 *    7. A client with the public key "mgPublicKey1" requests to recover the file "foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *    8. A client with the public key "mgPublicKey222" sends a outgoing transfer cancelled message, for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received a outgoing transfer cancelled message from the unknown client. This message was ignored. Client public key: [mgPublicKey222].
	 *    9. A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message, for the file transfer with handle "2" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received a outgoing transfer cancelled message with unknown handle. This message was ignored. Handle: 2. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey1].
	 *   10. A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message with handle "1", for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following error message was logged: The worker received a outgoing transfer cancelled message from the client. This message was successfully accepted. File path: [playpenDir/foo1]. Client public key: [mgPublicKey1]. Handle: 1. Amount of data uploaded: 12 bytes
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   11. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   12. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1;";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *   13. Copy the file "foo1" to playpen directory
	 *   14. Copy the file "foo2" to storage directory
	 *   15. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *   16. A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message, for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following error message was logged: The worker received a outgoing transfer cancelled message from the client. This message was successfully accepted. File path: [storageDir/foo1].  Handle: 1. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   17. A client with the public key "mgPublicKey1" sends a file transfer cancelled message, for the file transfer with handle "2" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received a outgoing transfer cancelled message from the client. This message was ignored, because a error already ocurred. File path: [playpenDir/foo2]. Handle: 2. Amount of data uploaded: 12 bytes.  Client public key: [mgPublicKey1].
	 *   18. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   19. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   20. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   21. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   22. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   23. Copy the file "foo1" to playpen directory
	 *   24. Copy the file "foo2" to storage directory
	 *   25. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *   26. A client with the public key "mgPublicKey222" sends a outgoing transfer cancelled message, for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following error message was logged: The worker received a file transfer cancelled message from the client. This message was successfully accepted. File path: [playpenDir/foo1]. Handle: 1. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   27. A client with the public key "mgPublicKey222" sends a outgoing transfer cancelled message, for the file transfer with handle "2" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received file transfer cancelled message from the client. This message was ignored, because a error already ocurred. File path: [storageDir/foo2]. Handle: 2. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey222].
	 *           
	 */
	@ReqTest(test=" AT-081.10", reqs="REQ080")
	@Test public void test_at_081_10_FileTransferCancelled() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();
		
		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);
		
		//Copy the file "foo1" to playpen directory
		String completeFile1Path = playpenDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
	
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "foo1");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message,
		// for the file transfer with handle "2" and 12 bytes of written data - expect a warn to be logged
		req_081_Util.receiveFileTransferCancelledWithUnknownHandle(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(2, "", "", "", myGrid1ID), 12);
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message,
		// for the file transfer with handle "1" and 12 bytes of written data - expect a error to be logged
		req_081_Util.receiveFileTransferCancelled(component, workerClient, myGrid1ID.getPublicKey(), 
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID), completeFile1Path, 12);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		List<TransferHandle> handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID));
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID, handles);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1", playpenDir, storageDir, 1);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to storage directory
		String completeFile2Path = storageDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$PLAYPEN"+File.separator+"foo1", "$STORAGE"+File.separator+"foo2");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message,
		// for the file transfer with handle "1" and 12 bytes of written data - expect a error to be logged
		req_081_Util.receiveFileTransferCancelled(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID), completeFile1Path, 12);
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message,
		// for the file transfer with handle "2" and 12 bytes of written data - expect a warn to be logged
		req_081_Util.receiveFileTransferCancelledOnWorkerWithError(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid1ID), completeFile2Path, 12);
		
		//The master peer sends a stopWorking message to the Worker
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid");
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);

		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo2; $PLAYPEN/touch foo3"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid2ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo2; $PLAYPEN"+File.separator+"touch foo3", playpenDir, storageDir, 2);	
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		
		//Copy the file "foo1" to storage directory
		completeFile1Path = storageDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", "foo2");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message,
		// for the file transfer with handle "1" and 12 bytes of written data - expect a error to be logged
		req_081_Util.receiveFileTransferCancelled(component, workerClient, myGrid2ID.getPublicKey(),
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid2ID), completeFile1Path, 12);
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer cancelled message,
		// for the file transfer with handle "2" and 12 bytes of written data - expect a warn to be logged
		req_081_Util.receiveFileTransferCancelledOnWorkerWithError(component, workerClient, myGrid2ID.getPublicKey(),
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid2ID), completeFile2Path, 12);
	}

	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1]."
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    6. Copy the file "foo1" to playpen directory
	 *    7. A client with the public key "mgPublicKey1" requests to recover the file "foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *    8. A client with the public key "mgPublicKey222" sends a outgoing transfer failed message, for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received a outgoing transfer failed message from the unknown client. This message was ignored. Client public key: [mgPublicKey222].
	 *    9. A client with the public key "mgPublicKey1" sends a outgoing transfer failed message, for the file transfer with handle "2" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received a outgoing transfer failed message with unknown handle. This message was ignored. Handle: 2. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey1].
	 *   10. A client with the public key "mgPublicKey1" sends a outgoing transfer failed message, for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following error message was logged: The worker received a outgoing transfer failed message from the client. This message was successfully accepted. File path: [playpenDir/foo1]. Client public key: [mgPublicKey1]. Handle: 1. Amount of data uploaded: 12 bytes
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   11. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   12. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *   13. Copy the file "foo1" to playpen directory
	 *   14. Copy the file "foo2" to storage directory
	 *   15. A client with the public key "mgPublicKey1" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *   16. A client with the public key "mgPublicKey1" sends a outgoing transfer failed message, for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following error message was logged: The worker received a outgoing transfer failed message from the client. This message was successfully accepted. File path: [playpenDir/foo1].  Handle: 1. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   17. A client with the public key "mgPublicKey1" sends a file transfer failed message, for the file transfer with handle "2" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received a outgoing transfer failed message from the client. This message was ignored, because a error already ocurred. File path: [storageDir/foo2]. Handle: 2. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey1].
	 *   18. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   19. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
  	 * 20. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   21. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   22. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   23. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *   24. A client with the public key "mgPublicKey222" sends a outgoing transfer failed message, for the file transfer with handle "1" and 12 bytes of written data;
	 *           * Verify if the following error message was logged: The worker received a outgoing transfer failed message from the client. This message was successfully accepted. File path: [playpenDir/foo1]. Handle: 1. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to send the client an error ocurred message with the APPLICATION_ERROR type
	 *   25. A client with the public key "mgPublicKey222" sends a outgoing transfer failed message, for the file transfer with handle "2" and 12 bytes of written data;
	 *           * Verify if the following warn message was logged: The worker received outgoing transfer failed message from the client. This message was ignored, because a error already ocurred. File path: [storageDir/foo2]. Handle: 2. Amount of data uploaded: 12 bytes. Client public key: [mgPublicKey222].
	 *           
	 */
	@ReqTest(test=" AT-081.11", reqs="REQ080")
	@Test public void test_at_081_11_FileTransferFailed() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker();
		
		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		RandomNumberUtil.setSeed(0L);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);
		
		//Copy the file "foo1" to playpen directory
		String completeFile1Path = playpenDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "foo1");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer failed message,
		// for the file transfer with handle "2" and 12 bytes of written data - expect a warn to be logged
		req_081_Util.receiveFileTransferFailedWithUnknownHandle(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(2, "", "", "", myGrid1ID), 12, new Exception());
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer failed message,
		// for the file transfer with handle "1" and 12 bytes of written data - expect a error to be logged
		req_081_Util.receiveFileTransferFailed(component, workerClient, myGrid1ID.getPublicKey(), 
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID), completeFile1Path, 12, new Exception());
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		List<TransferHandle> handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID));
		
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID, handles);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1", playpenDir, storageDir, 1);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to storage directory
		String completeFile2Path = storageDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$PLAYPEN"+File.separator+"foo1", "$STORAGE"+File.separator+"foo2");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer failed message,
		// for the file transfer with handle "1" and 12 bytes of written data - expect a error to be logged
		req_081_Util.receiveFileTransferFailed(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID),
				completeFile1Path, 12, new Exception());
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer failed message,
		// for the file transfer with handle "2" and 12 bytes of written data - expect a warn to be logged
		req_081_Util.receiveFileTransferFailedOnWorkerWithError(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid1ID),
				completeFile2Path, 12, new Exception());
		
		//The master peer sends a stopWorking message to the Worker
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		RandomNumberUtil.setSeed(0L);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);

		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo2; $PLAYPEN/touch foo3"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid2ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo2; $PLAYPEN"+File.separator+"touch foo3", playpenDir, storageDir, 2);		
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		//Copy the file "foo1" to storage directory
		completeFile1Path = storageDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", "foo2");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer failed message,
		// for the file transfer with handle "1" and 12 bytes of written data - expect a error to be logged
		req_081_Util.receiveFileTransferFailed(component, workerClient, myGrid2ID.getPublicKey(),
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid2ID),
				completeFile1Path, 12, new Exception());
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer failed message,
		// for the file transfer with handle "2" and 12 bytes of written data - expect a warn to be logged
		req_081_Util.receiveFileTransferFailedOnWorkerWithError(component, workerClient, myGrid2ID.getPublicKey(),
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid2ID),
				completeFile2Path, 12, new Exception());
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *    5. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1]."
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    6. Copy the file "foo1" to playpen directory
	 *    7. Copy the file "foo2" to playpen directory
	 *    8. A client with the public key "mgPublicKey1" requests to recover the file "foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *    9. The master peer commands the Worker to work for the client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: Cleaning Worker.
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   10. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   11. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   12. Copy the file "foo1" to storage directory
	 *   13. Copy the file "foo2" to playpen directory
	 *   14. A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *   15. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following debug message was logged: Cleaning Worker.
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   16. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   17. A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *   18. Pause the Worker;
	 *           * Verify if the following info message was logged: "Worker has been PAUSED."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to OWNER."
	 *           * Expect the Worker to send the peer a status changed message, with the OWNER status
	 *   19. Resume the Worker;
	 *           * Verify if the following info message was logged: "Worker has been RESUMED."
	 *           * Verify if the following debug message was logged: "Status changed from OWNER to IDLE."
	 *           * Verify if the ControlClient received the operation succeed message
	 *   20. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   21. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   22. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1]."
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *   23. Copy the file "foo1" to storage directory
	 *   24. A client with the public key "mgPublicKey1" requests to recover the file "$STORAGE/foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *   25. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   26. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   27. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   28. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; $PLAYPEN/touch foo2"; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1]."
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *   29. Copy the file "foo1" to playpen directory
	 *   30. Copy the file "foo2" to playpen directory
	 *   31. A client with the public key "mgPublicKey1" requests to recover the file "foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *   32. Stop the Worker with the correct public key;
	 *           * Verify if the following debug message was logged: Cleaning Worker.
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Verify if the following info message was logged: "Worker has been successfully shutdown."
	 *   33. Start a Worker with the idleness detector DISABLED;
	 *   34. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   35. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   36. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey333";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey333]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   37. A client with the public key "mgPublicKey333" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   38. A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey333].
	 *   39. Copy the file "foo1" to storage directory
	 *   40. Copy the file "foo2" to playpen directory
	 *   41. A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *   42. A client with the public key "mgPublicKey333" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   43. A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   44. Copy the file "foo2" to playpen directory
	 *   45. A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *   46. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey444";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey444]."
	 *           * Verify if the following debug message was logged: Cleaning Worker.
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   47. A client with the public key "mgPublicKey444" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   48. A client with the public key "mgPublicKey444" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey444].
	 *   49. Copy the file "foo1" to storage directory
	 *   50. Copy the file "foo2" to playpen directory
	 *   51. A client with the public key "mgPublicKey444" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey444].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey444].
	 *           * Expect the Worker to start the transfer;
	 *   52. Pause the Worker;
	 *           * Verify if the following info message was logged: "Worker has been PAUSED."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to OWNER."
	 *           * Expect the Worker to send the peer a status changed message, with the OWNER status
	 *   53. Resume the Worker;
	 *           * Verify if the following info message was logged: "Worker has been RESUMED."
	 *           * Verify if the following debug message was logged: "Status changed from OWNER to IDLE."
	 *           * Verify if the ControlClient received the operation succeed message
	 *   54. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   55. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey333";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey333]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   56. A client with the public key "mgPublicKey333" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   57. A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   58. Copy the file "foo2" to playpen directory
	 *   59. A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *   60. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   61. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   62. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey333";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey333]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   63. A client with the public key "mgPublicKey333" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID].
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   64. A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey333].
	 *   65. Copy the file "foo2" to playpen directory
	 *   66. A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *   67. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   68. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey333";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey333]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   69. A client with the public key "mgPublicKey333" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   70. A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey333].
	 *   71. Copy the file "foo2" to playpen directory
	 *   72. A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [storageDir/foo1]. Handle: 1. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo2]. Handle: 2. Client public key: [mgPublicKey333].
	 *           * Expect the Worker to start the transfer;
	 *   73. Stop the Worker with the correct public key;
	 *           * Verify if the following debug message was logged: Cleaning Worker.
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "1";
	 *           * Expect the Worker to cancel the outgoing file transfer with the handle "2";
	 *           * Verify if the following info message was logged: "Worker has been successfully shutdown."
	 * 
	 */
	@ReqTest(test=" AT-081.12", reqs="REQ080")
	@Test public void test_at_081_12_WorkerIsPreemptedWhileUploadingFile() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker(false);
		
		CommuneLogger logger = component.getLogger();

		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		RandomNumberUtil.setSeed(0L);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);
		
		//Copy the file "foo1" to playpen directory
		String file1Name = "foo1";
		String completeFile1Path = playpenDir + File.separator + file1Name;
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		String file2Name = "foo2";
		String completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, file1Name, file2Name);
		
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");

		//The master peer commands the Worker to work for the client with the public key "mgPublicKey222"
		List<TransferHandle> handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "file1", "file1", "", myGrid2ID));
		handles.add(new OutgoingTransferHandle(2, "file2", "file2" , "", myGrid2ID));
		
		Thread.sleep(1000);
		req_092_Util.workForMyGridOnAllocatedForMyGridWorkerWithFileOnTransfer(
				component, wmc, "mgPublicKey222", false, handles);
		worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey222" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid2ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2", playpenDir, storageDir, 1);
		
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		//Copy the file "foo1" to storage directory
		completeFile1Path = storageDir + File.separator + file1Name;
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);

		
		//A client with the public key "mgPublicKey222" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid2ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid2ID));
		
		workerClient = req_079_Util.startWorkSuccessfullyWithFileOnTransfer(component, worker,
				myGrid2ID, false, handles);
		
		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2",
				playpenDir, storageDir, 2);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);
		
		//Pause the Worker
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid2ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid2ID));
		
		Thread.sleep(1000);
		req_087_Util.pauseAllocatedForMyGridWorkerWithFileOnTransfer(component, wmc, false, handles);
		
		//Resume the Worker
		req_088_Util.resumeOwnerWorker(wmc, component);
	
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, myGrid1ID.getPublicKey());
		worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		component.setLogger(logger);
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1", playpenDir, storageDir, 3);
		
		//Copy the file "foo1" to storage directory
		completeFile1Path = playpenDir + File.separator + file1Name;
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(),
				workerClient, playpenDir, storageDir, file1Name);

		//The master peer sends a stopWorking message to the Worker
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorkerWithFileOnTranfer(component, wmc, peerID.getPublicKey(), false, handles);
		
		//The master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, myGrid1ID.getPublicKey());
		worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);

		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1; $PLAYPEN/touch foo2"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2", playpenDir, storageDir, 4);
		
		//Copy the file "foo1" to playpen directory
		completeFile1Path = playpenDir + File.separator + file1Name;
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(),
				workerClient, playpenDir, storageDir, file1Name, file2Name);
		
		//Stop the Worker
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid1ID));
		
		req_120_Util.stopWorkerWithFileOnTransfer(component, false, handles);
		
		//Start a Worker with the idleness detector DISABLED
		component = req_004_Util.startWorker();
		logger = component.getLogger();

		//The master peer sends a setPeer message to the Worker
		wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey333"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey333");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey333" sends a startWork message
		DeploymentID myGrid3ID = new DeploymentID(new ContainerID("mg3UserName", "mg3Server", "mg3Module", "mgPublicKey333"), "myGrid3");
		
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid3ID);

		//A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid3ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid3ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2",
				playpenDir, storageDir, 0);	
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);

		//Copy the file "foo1" to storage directory
		completeFile1Path = storageDir + File.separator + file1Name;
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid3ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);

		//A client with the public key "mgPublicKey222" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid1ID));
		
		workerClient = req_079_Util.startWorkSuccessfullyWithFileOnTransfer(component, worker, myGrid3ID, false, handles);

		//A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid3ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid3ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2", playpenDir, storageDir, 1);		

		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid3ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);

		//The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client
		// with the public key "mgPublicKey444"
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid1ID));

		Thread.sleep(1000);
		
		rwmc = req_121_Util.workForMyGridOnAllocatedForMyGridWorkerWithFileOnTransfer(component, "peerPubKey", "mgPublicKey444", false, handles);
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);
		
		//A client with the public key "mgPublicKey444" sends a startWork message
		DeploymentID myGrid4ID = new DeploymentID(new ContainerID("mg4UserName", "mg4Server", "mg4Module", "mgPublicKey444"), "myGrid4");
		
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid4ID);

		//A client with the public key "mgPublicKey444" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid4ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid4ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2",
				playpenDir, storageDir, 2);		
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);

		//Copy the file "foo1" to storage directory
		completeFile1Path = storageDir + File.separator + file1Name;
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey444" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid4ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);

		//Pause the Worker
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid1ID));
		
		Thread.sleep(1000);
		req_087_Util.pauseAllocatedForMyGridWorkerWithFileOnTransfer(component, wmc, false, handles);
		
		//Resume the Worker
		req_088_Util.resumeOwnerWorker(wmc, component);

		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey333"
		rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey333");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey333" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid3ID);

		//A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid3ID.getPublicKey());
		
		component.setLogger(logger);
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid3ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2", playpenDir, storageDir, 3);		
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);

		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid3ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);

		//The master peer sends a stopWorking message to the Worker
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid1ID));
		
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorkerWithFileOnTranfer(component, wmc, peerID.getPublicKey(), false, handles);

		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey333"
		rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey333");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey333" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid3ID);

		//A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid3ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid3ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2",
				playpenDir, storageDir, 4);	
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);

		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid3ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);
		
		//The master peer commands the Worker to work for a peer with the publicKey "peerPubKey222"
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid1ID));
		
		req_006_Util.workForPeerOnAllocatedForMyGridWorkerWithFileOnTranfer(component, wmc, peerID.getPublicKey(), 
				"peerPubKey222", false, handles);

		//The remote peer with the public key "peerPubKey222" commands the Worker to work for
		// the remote client with the public key "mgPublicKey333"
		rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey222", myGrid3ID.getPublicKey());
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey333" sends a startWork message
		RandomNumberUtil.setSeed(0L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid3ID);

		//A client with the public key "mgPublicKey333" tries to execute the remote command "touch $STORAGE/foo1; $PLAYPEN/touch foo2"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid3ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid3ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo1; $PLAYPEN"+File.separator+"touch foo2",
				playpenDir, storageDir, 5);	
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);

		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + file2Name;
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey333" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid3ID.getPublicKey(),
				workerClient, playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", file2Name);
		
		//Stop the Worker
		handles = new ArrayList<TransferHandle>();
		handles.add(new OutgoingTransferHandle(1, "", "", "", myGrid1ID));
		handles.add(new OutgoingTransferHandle(2, "", "", "", myGrid1ID));
		
		req_120_Util.stopWorkerWithFileOnTransfer(component, false, handles);
	}
	
	/**
	 *    1.  Start a Worker with the idleness detector DISABLED;
	 *    2. The master peer sends a setPeer message to the Worker;
	 *           * Verify if the following info message was logged: The peer [peerID] set itself as manager of this Worker.
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *    3. The master peer commands the Worker to work for the client with the public key "mgPublicKey1";
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a local consumer. Local consumer public key: [mgPublicKey1]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *    4. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch playpenDir/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1]."
	 *           * Expect if the worker schedules an execution action HELP. The execution directory should be the playpen.
	 *           * Expect the schedule action to send a executionResult to the WorkerClient
	 *    5. Copy the file "foo1" to playpen directory
	 *    6. A client with the public key "mgPublicKey1" requests to recover the file "foo1";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *    7. A client with the public key "mgPublicKey222" sends a outgoing transfer completed message, for the file transfer with handle "1" and size 256 bytes;
	 *           * Verify if the following debug message was logged: The worker received a outgoing transfer completed message from the unknown client. This message was ignored. Client public key: [mgPublicKey222].
	 *    8. A client with the public key "mgPublicKey1" sends a outgoing transfer completed message, for the file transfer with handle "2" and size 256 bytes;
	 *           * Verify if the following warn message was logged: The worker received a outgoing transfer completed message with unknown handle. This message was ignored. Handle: 2. Client public key: [mgPublicKey1].
	 *    9. A client with the public key "mgPublicKey1" sends a outgoing transfer completed message with handle "1", for the file transfer with handle "1" and size 256 bytes;
	 *           * Verify if the following debug message was logged: The worker received a outgoing transfer completed message from the client. Upload finished. File path: [playpenDir/foo1]. Handle: 1. Amount of data uploaded: 256 bytes. Client public key: [mgPublicKey1].
	 *           * Verify if the following info message was logged: All current uploading files has been finished.
	 *   10. A client with the public key "mgPublicKey1" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   11. A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1; touch $STORAGE/foo2";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $STORAGE/foo1; $PLAYPEN/touch foo2; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey1].
	 *   12. Copy the file "foo1" to playpen directory
	 *   13. Copy the file "foo2" to storage directory
	 *   14. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [Dir/foo2]. Handle: 2. Client public key: [mgPublicKey1].
	 *           * Expect the Worker to start the transfer;
	 *   15. A client with the public key "mgPublicKey1" sends a outgoing transfer completed message with handle "1", for the file transfer with handle "1" and size 256 bytes;
	 *           * Verify if the following debug message was logged: The worker received a outgoing transfer completed message from the client. Upload finished. File path: [storageDir/foo1]. Handle: 1. Amount of data uploaded: 256 bytes. Client public key: [mgPublicKey1].
	 *   16. A client with the public key "mgPublicKey1" sends a outgoing transfer completed message with handle "2", for the file transfer with handle "2" and size 256 bytes;
	 *           * Verify if the following debug message was logged: The worker received a outgoing transfer completed message from the client. Upload finished. File path: [playpenDir/foo1]. Handle: 2. Amount of data uploaded: 256 bytes. Client public key: [mgPublicKey1].
	 *           * Verify if the following debug message was logged: All current uploading files has been finished.
	 *   17. The master peer sends a stopWorking message to the Worker;
	 *           * Verify if the following info message was logged: "This Worker was commanded to stop working for the current client."
	 *           * Verify if the following debug message was logged: "Cleaning Worker."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_MYGRID to IDLE."
	 *           * Expect the Worker to send a status changed message to the peer, with the IDLE status
	 *   18. The master peer sends a workForPeer message to the Worker;
	 *           * Verify if the following info message was logged: "Peer commanded this Worker to work for a remote peer. Remote peer public key: [peerPubKey]."
	 *           * Verify if the following debug message was logged: "Status changed from IDLE to ALLOCATED_FOR_PEER."
	 *           * Expect the Worker to send the peer an allocated for peer status changed message, with a stub to the Remote Worker Management remote object
	 *   19. The remote peer with the public key "peerPubKey" commands the Worker to work for the remote client with the public key "mgPublicKey222";
	 *           * Verify if the following info message was logged: "Remote peer commanded this Worker to work for a remote consumer. Remote consumer public key: [mgPublicKey222]."
	 *           * Verify if the following debug message was logged: "Status changed from ALLOCATED_FOR_PEER to ALLOCATED_FOR_MYGRID."
	 *           * Expect the Worker to send the remote peer an allocated for mygrid status changed message, with a stub to the Worker remote object
	 *   20. A client with the public key "mgPublicKey222" sends a startWork message;
	 *           * Verify if the following info message was logged: Worker is ready to start working for client [ClientID1].
	 *           * Verify if the following info message was logged: "Cleaning Worker."
	 *           * Expect the Worker to send the client a Worker is Ready message
	 *   21. A client with the public key "mgPublicKey222" tries to execute the remote command "touch $PLAYPEN/foo1";
	 *           * Verify if the following info message was logged: "Command scheduled to execution. Command: touch $PLAYPEN/foo1; RequestID: requestID ; Environment variables: ; Client public key: [mgPublicKey222].
	 *   22. Copy the file "foo1" to playpen directory
	 *   23. Copy the file "foo2" to storage directory
	 *   24. A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2";
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The transfer request was accepted and the worker is starting to upload the file. File path: [playpenDir/foo1]. Handle: 1. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *           * Verify if the following debug message was logged: The client tried to recover the files. The worker accepted the transfer request and is starting to upload the file. File path: [storageDir/foo2]. Handle: 2. Client public key: [mgPublicKey222].
	 *           * Expect the Worker to start the transfer;
	 *   25. A client with the public key "mgPublicKey222" sends a outgoing transfer completed message , for the file transfer with handle "1" and size 256 bytes;
	 *           * Verify if the following debug message was logged: The worker received a outgoing transfer completed message from the client. Upload finished. File path: [playpenDir/foo1]. Handle: 1. Amount of data uploaded: 256 bytes. Client public key: [mgPublicKey1].
	 *   26. A client with the public key "mgPublicKey222" sends a outgoing transfer completed message, for the file transfer with handle "2" and size 256 bytes;
	 *           * Verify if the following debug message was logged: The worker received a outgoing transfer completed message from the client. Upload finished. File path: [storageDir/foo1]. Handle: 2. Amount of data uploaded: 256 bytes. Client public key: [mgPublicKey1].
	 *           * Verify if the following info message was logged: All current uploading files has been finished.
	 * 
	 */
	@ReqTest(test=" AT-081.13", reqs="REQ080")
	@Test public void test_at_081_13_FileTransferCompleted() throws Exception {
		//Start Worker with idleness detector DISABLED
		WorkerComponent component = req_004_Util.startWorker(false);
		
		//Master peer sends a setPeer message
		WorkerManagementClient wmc = req_090_Util.setKnownPeer(component, peerID, WorkerStatus.IDLE);
		
		//Master peer commands the Worker to work for the client with the public key "mgPublicKey1"
		req_092_Util.workForMyGridOnIdleWorker(component, wmc, "mgPublicKey1");
		Worker worker = req_092_Util.beginAllocationCompleted(component, wmc);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		DeploymentID myGrid1ID = new DeploymentID(new ContainerID("mgUserName", "mgServer", "mgModule", "mgPublicKey1"), "myGrid");
		
		RandomNumberUtil.setSeed(1L);
		WorkerClient workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		String playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		File pDir = new File(playpenPath);
		
		String storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		File sDir = new File(storagePath);
		
		long requestID = 1;
		Map<String, String> envVars = new HashMap<String, String>();
		String playpenDir = pDir.getAbsolutePath();
		String storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID, requestID, envVars, "echo echo", 
				playpenDir, storageDir, 0);
		
		//Copy the file "foo1" to playpen directory
		String completeFile1Path = playpenDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//A client with the public key "mgPublicKey1" requests to recover the file "foo1"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "foo1");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer completed message,
		// for the file transfer with handle "2" and 12 bytes of written data
		req_081_Util.receiveFileTransferCompletedWithUnknownHandle(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(2, "", "", "", myGrid1ID),	12);
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer completed message,
		// for the file transfer with handle "1" and 12 bytes of written data
		req_081_Util.receiveFileTransferCompletedForLastUploadingFile(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID),	completeFile1Path, 12);
		
		//A client with the public key "mgPublicKey1" sends a startWork message
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfullyCleaning(component, worker, myGrid1ID);
		
		//A client with the public key "mgPublicKey1" tries to execute the remote command "touch $PLAYPEN/foo1"
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid1ID,
				requestID, envVars, "touch $PLAYPEN"+File.separator+"foo1", playpenDir, storageDir, 1);
		
		//Copy the file "foo1" to playpen directory
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to storage directory
		String completeFile2Path = storageDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);
		
		//A client with the public key "mgPublicKey222" requests to recover the file "$PLAYPEN/foo1", "$STORAGE/foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid1ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$PLAYPEN"+File.separator+"foo1", "$STORAGE"+File.separator+"foo2");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer completed message,
		// for the file transfer with handle "1" and 12 bytes of written data
		req_081_Util.receiveFileTransferCompleted(component, workerClient, myGrid1ID.getPublicKey(), 
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid1ID),
				completeFile1Path, 12);
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer completed message,
		// for the file transfer with handle "2" and 12 bytes of written data
		req_081_Util.receiveFileTransferCompletedForLastUploadingFile(component, workerClient, myGrid1ID.getPublicKey(),
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid1ID),	completeFile2Path, 12);
		
		//The master peer sends a stopWorking message to the Worker
		Thread.sleep(1000);
		req_091_Util.stopWorkingOnAllocatedForMyGridWorker(component, wmc, peerID.getPublicKey());
		
		//The master peer sends a workForPeer message to the Worker
		req_006_Util.workForPeerOnIdleWorker(component, wmc, peerID.getPublicKey(), "peerPubKey");
		
		//The remote peer with the public key "peerPubKey" commands the Worker to work for
		// the remote client with the public key "mgPublicKey222"
		RemoteWorkerManagementClient rwmc = req_121_Util.workForMyGridOnAllocatedForPeerWorker(component, "peerPubKey", "mgPublicKey222");
		worker = req_121_Util.beginAllocationCompleted(component, rwmc);

		//A client with the public key "mgPublicKey222" sends a startWork message
		DeploymentID myGrid2ID = new DeploymentID(new ContainerID("mg2UserName", "mg2Server", "mg2Module", "mgPublicKey222"), "myGrid2");
		
		RandomNumberUtil.setSeed(1L);
		Thread.sleep(1000);
		workerClient = req_079_Util.startWorkSuccessfully(component, worker, myGrid2ID);

		//A client with the public key "mgPublicKey222" tries to execute the remote command "touch $STORAGE/foo2; touch $PLAYPEN/foo3"
//		storageDir = storageRoot + File.separator + WorkerAcceptanceUtil.generateHexadecimalCodedString(
//				myGrid2ID.getPublicKey());
		
		req_084_Util.remoteExecutionWithSuccess(component, worker, workerClient, myGrid2ID,
				requestID, envVars, "touch $STORAGE"+File.separator+"foo2; touch $PLAYPEN"+File.separator+"foo3",
				playpenDir, storageDir, 2);		
		
		playpenPath = component.getDAO(EnvironmentDAO.class).getPlaypenDir();
		pDir = new File(playpenPath);
		
		storagePath = component.getDAO(EnvironmentDAO.class).getStorageDir();
		sDir = new File(storagePath);
		
		envVars = new HashMap<String, String>();
		playpenDir = pDir.getAbsolutePath();
		storageDir = sDir.getAbsolutePath();
		envVars.put("STORAGE", storageDir);
		envVars.put("PLAYPEN", playpenDir);
		
		//Copy the file "foo1" to storage directory
		completeFile1Path = storageDir + File.separator + "foo1";
		WorkerAcceptanceUtil.createFile(completeFile1Path);
		
		//Copy the file "foo2" to playpen directory
		completeFile2Path = playpenDir + File.separator + "foo2";
		WorkerAcceptanceUtil.createFile(completeFile2Path);

		//A client with the public key "mgPublicKey222" requests to recover the file "$STORAGE/foo1", "foo2"
		req_081_Util.requestToRecoverFilesWithSuccess(component, requestID, myGrid2ID.getPublicKey(), workerClient,
				playpenDir, storageDir, "$STORAGE"+File.separator+"foo1", "foo2");
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer completed message,
		// for the file transfer with handle "1" and 12 bytes of written data
		req_081_Util.receiveFileTransferCompleted(component, workerClient, myGrid2ID.getPublicKey(), 
				new OutgoingTransferHandle(1, completeFile1Path, completeFile1Path, "", myGrid2ID),
				completeFile1Path, 12);
		
		//A client with the public key "mgPublicKey1" sends a outgoing transfer completed message,
		// for the file transfer with handle "2" and 12 bytes of written data
		req_081_Util.receiveFileTransferCompletedForLastUploadingFile(component, workerClient, myGrid2ID.getPublicKey(),
				new OutgoingTransferHandle(2, completeFile2Path, completeFile2Path, "", myGrid2ID),	completeFile2Path, 12);
	}
}